Skip to content

Add plain vs range syntax section to container queries guide#44014

Open
pepelsbey wants to merge 2 commits intomdn:mainfrom
pepelsbey:equality-vs-range
Open

Add plain vs range syntax section to container queries guide#44014
pepelsbey wants to merge 2 commits intomdn:mainfrom
pepelsbey:equality-vs-range

Conversation

@pepelsbey
Copy link
Copy Markdown
Member

@pepelsbey pepelsbey commented May 5, 2026

Description

Documents the difference between the : (plain) and = (range) forms of style() in container style queries:

  • Adds a new section to the container size and style queries guide.
  • Adds a summary in the @container reference linking to the guide.

Motivation

To clear the difference between style(--n: 3) and style(--n = 3).

Additional details

@pepelsbey pepelsbey requested a review from a team as a code owner May 5, 2026 14:00
@pepelsbey pepelsbey requested review from hamishwillee and removed request for a team May 5, 2026 14:00
@github-actions github-actions Bot added Content:CSS Cascading Style Sheets docs size/m [PR only] 51-500 LoC changed labels May 5, 2026
@pepelsbey
Copy link
Copy Markdown
Member Author

@nchevobbe let me know if it fully covers the feature

@github-actions
Copy link
Copy Markdown
Contributor

github-actions Bot commented May 5, 2026

Preview URLs (2 pages)

Flaws (12)

Note! 1 document with no flaws that don't need to be listed. 🎉

Found an unexpected or unresolvable flaw? Please report it here.

URL: /en-US/docs/Web/CSS/Reference/At-rules/@container
Title: @container CSS at-rule
Flaw count: 12

  • broken_links:
    • Link /en-US/docs/Web/CSS/Reference/Values/block-contents doesn't resolve
    • Link /en-US/docs/Web/CSS/Reference/Values/size-feature doesn't resolve
    • Link /en-US/docs/Web/CSS/Reference/Values/scroll-state-feature doesn't resolve
    • Link /en-US/docs/Web/CSS/Reference/Values/function-token doesn't resolve
    • Link /en-US/docs/Web/CSS/Reference/Values/any-value doesn't resolve
    • and 7 more flaws omitted

(comment last updated: 2026-05-06 06:15:52)

@nchevobbe
Copy link
Copy Markdown
Contributor

@nchevobbe let me know if it fully covers the feature

I think so, at least it definitely helps understanding the differences
Maybe @dshin-moz can give it a read too to make sure it's all good :)

@dshin-moz
Copy link
Copy Markdown
Contributor

Yeah, this looks good - Only nitpick is the naming of the equality syntax. At least to me, at a glance, style(--n = 3) looks more like the equality syntax than style(--n: 3).

Technically it's <style-feature-plain> 1, so maybe a "plain match syntax," i.e. style(--n: 3) vs. "range equality syntax," a subset of the <style-range> syntax 2, i.e. style(--n = 3)?

@pepelsbey
Copy link
Copy Markdown
Member Author

@dshin-moz good point! It’s much clearer with plain vs range now and directly attached to the spec. Thanks!

@pepelsbey pepelsbey changed the title Add equality vs range syntax section to container queries guide Add plain vs range syntax section to container queries guide May 6, 2026

The global `revert` and `revert-layer` are invalid as values in a `<style-feature>` and cause the container style query to be false.

#### Plain (`:`) versus range (`=`) syntax
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Consider doing all as below. I see the point of comparing the two you have because they look similar and I guess doing = will be a gotcha. But in most cases you'll likely us this as an actual range - so > is far more likely.

Suggested change
#### Plain (`:`) versus range (`=`) syntax
#### Plain (`:`) versus range (`=`,`<`, `<=`, `>`, `>=`) syntax

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

OK, having read the guide now, I'd be tempted to call this range syntax, make it mostly about range syntax, and expand it out with some of the information in the guide.
This focuses currently on the comparision of the forms - but I see this as the reference which needs to mostly talk about what range syntax is, not how it compares.

Specifically

  1. The material in "To evaluate this form, the "
  2. The point that there is a syntax with three values. MORE important, make it clear that they don't evaluate in a daisy chain, which I just assumed.
  3. I'd keep the comparsion as a gotcha example. It is useful.

Thoughts?

- `style(--n = 3)` (range) parses both sides as a number, length, percentage, etc., and compares numerically. With the same `--n: calc(6/2)`, `style(--n = 3)` is true. The range syntax also supports `<`, `<=`, `>`, `>=`, three-value intervals such as `style(0 < --n < 10)`, and flexible operand ordering.

For the full rules and more examples, see [Plain versus range syntax in style queries](/en-US/docs/Web/CSS/Guides/Containment/Container_size_and_style_queries#plain_versus_range_syntax_in_style_queries) in the container style queries guide.

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@pepelsbey @dletorey Can you guys co-ordinate. I just reviewed a section on this topic in #44003

  1. FYI, the problem I raised with that PR is that this section is in "examples" but the content of all these examples is actually guide. Arguably all of this should be in a description. Possibly to much restructure for now.

  2. That PR didn't include a proper guide. This is better, but you might want to take the example from the other PR into this.

  3. The range syntax isn't a CSS declaration as I undersand it, from the sentence in previous section "The parameter of each style() is a single <style-feature>. A <style-feature> is a valid CSS declaration, a CSS property, or a <custom-property-name>.".

    • Whatever it is, we should forward reference earlier and link down here - i.e. make it clear earlier that there are effectively "boolean" comparision on computed values and range comparsion on numerical values.
  4. The range syntax has implications also in that it compares numbers, so presumably if you compare a property like color: red to a range it might be meaningless - I'm not sure how that would coerce either.

    Minimally it is worth noting here what the intent is - i.e. why it was added and where you can/cannot use it.

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

PS See my comments on th intro https://github.com/mdn/content/pull/44014/changes#r3206101519

Most of this is still valid. If you make it more about the range and less about the comparion of forms this should just work.

> [!NOTE]
> When declaring custom properties, consider using `@property` with the {{cssxref("@property/syntax","syntax")}} descriptor so the browser can properly compare computed values.

### Plain versus range syntax in style queries
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is all great. I'd argue a little of it should go in the reference, but even if it did it should all stay here too.

@pepelsbey
Copy link
Copy Markdown
Member Author

@hamishwillee I would wait for @dletorey’s PR to be merged (it’s more time-sensitive) and get back to it then, addressing your feedback, etc.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Content:CSS Cascading Style Sheets docs size/m [PR only] 51-500 LoC changed

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants